﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{
    class Hollow_cone_joints_with_flanged_contact_surfaces_Mounting_holes_Dimensions
    {
        public static void Mounting_holes_Dimensions(Dictionary<string, Object> data)
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //基本参数-----------------------------------------------------------------------------------------------------
            double scale = 1; //放大系数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);
            double type = Convert.ToDouble(data["type"]) * scale;

            //定义参数--------------------------------------------------------------------------------------------------
            /*double b1 = 6.8 * scale;
            double d1 = 32 * scale;
            double d2 = 23.998 * scale;
            double d3 = 17 * scale;
            double d4 = 23.28 * scale;
            double d5 = 23.8 * scale;
            double d6 = 2.5 * scale;
            double l1 = 23.8 * scale;
            double l2 = 3.2 * scale;
            double l3 = 11.4 * scale;
            double l4 = 13.4 * scale;
            double l5 = 0.8 * scale;
            double l6 = 1 * scale;
            double l7 = 2 * scale;
            double r1 = 1.5 * scale;
            double t = 0.0015 * scale;*/

            double b1 = Convert.ToDouble(data["b1"]) * scale;
            double d1 = Convert.ToDouble(data["d1"]) * scale;
            double d2 = Convert.ToDouble(data["d2"]) * scale;
            double d3 = Convert.ToDouble(data["d3"]) * scale;
            double d4 = Convert.ToDouble(data["d4"]) * scale;
            double d5 = Convert.ToDouble(data["d5"]) * scale;
            double d6 = Convert.ToDouble(data["d6"]) * scale;
            double l1 = Convert.ToDouble(data["l1"]) * scale;
            double l2 = Convert.ToDouble(data["l2"]) * scale;
            double l3 = Convert.ToDouble(data["l3"]) * scale;
            double l4 = Convert.ToDouble(data["l4"]) * scale;
            double l5 = Convert.ToDouble(data["l5"]) * scale;
            double l6 = Convert.ToDouble(data["l6"]) * scale;
            double l7 = Convert.ToDouble(data["l7"]) * scale;
            double r1 = Convert.ToDouble(data["r1"]) * scale;
            double t = Convert.ToDouble(data["t"]) * scale;

            //定义点-----------------------------------------------------------------------------------------------------------------------------------
            //第一部分点------------------------------------------------------------------------------
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(v1.X + d4 * 1.5, v1.Y);
            Vector2 v3 = new Vector2(v1.X + fun.CalDistance(v1, v2) / 2, v1.Y + fun.CalDistance(v1, v2) / 2);
            Vector2 v4 = fun.mirrorpoint(v3, v1, v2);
            Vector2 v5 = fun.Inters(v1, v2, v3, v4);
            Vector2 v6 = fun.getPointForArcandLine(v5, fun.Polar(v5, 105 * pi / 180, d1), v5, new Arc(v5, d3 / 2, 0, 360));
            Vector2 v6_1 = new Vector2(v6.X, v6.Y + (d5 - d3) / 4);
            Vector2 v7 = fun.getPointForArcandLine(v5, fun.Polar(v5, 105 * pi / 180, d1), v5, new Arc(v5, d5 / 2, 0, 360));
            Vector2 v10 = fun.rotatePoint_Changed( v5, v6, 180);
            Vector2 v10_1 = fun.rotatePoint_Changed( v5, v6_1, 180);
            Vector2 v11 = fun.rotatePoint_Changed( v5, v7, 180);
            Vector2 v8 = fun.mirrorpoint(v10, v1, v2);
            Vector2 v8_1 = fun.mirrorpoint(v10_1, v1, v2);
            Vector2 v9 = fun.mirrorpoint(v11, v1, v2);
            Vector2 v12 = fun.mirrorpoint(v6, v1, v2);
            Vector2 v12_1 = fun.mirrorpoint(v6_1, v1, v2);
            Vector2 v13 = fun.mirrorpoint(v7, v1, v2);
            Vector2 v14 = new Vector2(v2.X + l4 * 2, v2.Y);
            Vector2 v15 = new Vector2(v14.X + l1 * 1.5, v14.Y);
            Vector2 v16 = new Vector2(v14.X + 5, v14.Y + d3 / 2);
            Vector2 v17 = new Vector2(v16.X + (l1 - l4) - 0.5, v16.Y);
            Vector2 v18 = new Vector2(v17.X + 0.5, v17.Y + 0.5);
            Vector2 v19 = new Vector2(v18.X, v14.Y + d5 / 2);
            Vector2 v20 = new Vector2(v19.X + l7, v19.Y);
            Vector2 v21 = new Vector2(v20.X, v20.Y + 0.1);
            Vector2 v22 = new Vector2(v21.X + l7, v21.Y);
            Vector2 v23 = new Vector2(v22.X, v22.Y - 0.1);
            Vector2 v24 = fun.Polar(v23, 2.87 * pi / 180, (l4 - (v23.X - v19.X) - 1) / Math.Cos(2.87 * pi / 180));
            Vector2 v24_1 = fun.Polar(v23, 2.87 * pi / 180, fun.CalDistance(v23, v24) * 2 / 3);
            Vector2 v25 = fun.Polar(v24, 45 * pi / 180, 1.41);
            Vector2 v26 = fun.mirrorpoint(v25, v14, v15);
            Vector2 v27 = fun.mirrorpoint(v24, v14, v15);
            Vector2 v27_1 = fun.mirrorpoint(v24_1, v14, v15);
            Vector2 v28 = fun.mirrorpoint(v23, v14, v15);
            Vector2 v29 = fun.mirrorpoint(v22, v14, v15);
            Vector2 v30 = fun.mirrorpoint(v21, v14, v15);
            Vector2 v31 = new Vector2(v30.X, v30.Y + (d5 - d3) / 2);
            Vector2 v32 = fun.mirrorpoint(v16, v14, v15);
            Vector2 v33 = new Vector2(v25.X, v25.Y + (d1 - d2) / 2);
            Vector2 v34 = new Vector2(v33.X - l1 * 1.2, v33.Y);
            Vector2 v35 = new Vector2(v34.X, v18.Y);
            Vector2 v36 = fun.mirrorpoint(v35, v14, v15);
            Vector2 v37 = fun.mirrorpoint(v34, v14, v15);
            Vector2 v38 = fun.mirrorpoint(v33, v14, v15);
            Vector2 v39 = new Vector2(v4.X, v4.Y - l1);
            Vector2 v40 = new Vector2(v39.X, v39.Y - l1 * 1.5);
            Vector2 v41 = new Vector2(v39.X + d4 / 2, v39.Y - 5);
            Vector2 v42 = new Vector2(v41.X, v41.Y - (l1 - l3));
            Vector2 v43 = new Vector2(v42.X + 0.1, v42.Y);
            Vector2 v44 = new Vector2(v43.X, v43.Y - l7);
            Vector2 v45 = new Vector2(v44.X - 0.1, v44.Y);
            Vector2 v46 = fun.Polar(v45, -(90 - 2.87) * pi / 180, (l4 - (v23.X - v19.X) - 1) / Math.Cos(2.87 * pi / 180));
            Vector2 v47 = fun.Polar(v46, -45 * pi / 180, 1.41);
            Vector2 v48 = fun.mirrorpoint(v47, v39, v40);
            Vector2 v49 = fun.mirrorpoint(v46, v39, v40);
            Vector2 v50 = fun.mirrorpoint(v45, v39, v40);
            Vector2 v51 = fun.mirrorpoint(v44, v39, v40);
            Vector2 v52 = fun.mirrorpoint(v43, v39, v40);
            Vector2 v53 = fun.mirrorpoint(v42, v39, v40);
            Vector2 v54 = fun.mirrorpoint(v41, v39, v40);
            Vector2 v55 = new Vector2(v54.X + (d5 - d3) / 2, v54.Y + (d5 - d3) / 2);
            Vector2 v55_1 = fun.Inters(v55, new Vector2(v55.X, v55.Y - d1), v54, v41);
            Vector2 v56 = new Vector2(v39.X - d1 / 2 * 1.2, v55.Y);
            Vector2 v57 = new Vector2(v56.X, v48.Y);
            Vector2 v59 = new Vector2(v41.X - (d5 - d3) / 2, v41.Y + (d5 - d3) / 2);
            Vector2 v59_1 = fun.mirrorpoint(v55_1, v39, v40);
            Vector2 v60 = fun.mirrorpoint(v56, v39, v40);
            Vector2 v61 = fun.mirrorpoint(v57, v39, v40);
            Vector2 v63 = new Vector2(v39.X - (v39.X - v54.X) / 2, v54.Y);
            Vector2 v62 = new Vector2(v63.X + (v39.X - v54.X) / 2.0 * 1 / 3, v63.Y);
            Vector2 v64 = new Vector2(v62.X, v62.Y - ((v41.Y - v42.Y) - l6));
            Vector2 v65 = new Vector2(v63.X, v64.Y);
            Vector2 v66 = fun.Inters(v65, fun.Polar(v65, -45 * pi / 180, d1), v53, v42);
            Vector2 v67 = fun.Inters(v64, fun.Polar(v64, -45 * pi / 180, d1), v53, v42);
            Vector2 v68 = fun.mirrorpoint(v62, v39, v40);
            Vector2 v69 = fun.mirrorpoint(v63, v39, v40);
            Vector2 v70 = fun.mirrorpoint(v64, v39, v40);
            Vector2 v71 = fun.mirrorpoint(v65, v39, v40);
            Vector2 v72 = fun.mirrorpoint(v66, v39, v40);
            Vector2 v73 = fun.mirrorpoint(v67, v39, v40);
            Vector2 v74 = new Vector2(v40.X, v64.Y - d2 / 4);

            if (type == 1 || type == 3/*type.Equals("A型空心锥柄") || type.Equals("C型空心锥柄")*/)
            {
                //作图部分-------------------------------------------------------------------------------------------------
                //第一部分--------------------------------------------------------------------------------------------
                //中心线
                Line centre_line1 = new Line(v1, v2);
                centre_line1.Layer = centre;
                centre_line1.Linetype = Linetype.Center;
                centre_line1.LinetypeScale = 5;
                dxf.AddEntity(centre_line1);

                Line centre_line2 = new Line(v3, v4);
                centre_line2.Layer = centre;
                centre_line2.Linetype = Linetype.Center;
                centre_line2.LinetypeScale = 5;
                dxf.AddEntity(centre_line2);

                //轮廓线
                fun.drawcircle(dxf, v5, d3 / 2, 0.3, contour);
                fun.drawcircle(dxf, v5, d5 / 2, 0.3, contour);
                fun.drawcircle(dxf, v5, d1 / 2, 0.3, contour);

                LwPolyline polyline1 = new LwPolyline();
                polyline1.Vertexes.Add(new LwPolylineVertex(v6));
                polyline1.Vertexes.Add(new LwPolylineVertex(v6_1));//0
                polyline1.Vertexes.Add(new LwPolylineVertex(v7));//1
                polyline1.Vertexes[1].Bulge = Math.Tan(90 * pi / 180 / 4);
                fun.PolyFill(dxf, polyline1, 0.3, contour);

                LwPolyline polyline2 = new LwPolyline();
                polyline2.Vertexes.Add(new LwPolylineVertex(v8));
                polyline2.Vertexes.Add(new LwPolylineVertex(v8_1));//0
                polyline2.Vertexes.Add(new LwPolylineVertex(v9));//1
                polyline2.Vertexes[1].Bulge = -Math.Tan((90) * pi / 180 / 4);
                fun.PolyFill(dxf, polyline2, 0.3, contour);

                LwPolyline polyline3 = new LwPolyline();
                polyline3.Vertexes.Add(new LwPolylineVertex(v10));
                polyline3.Vertexes.Add(new LwPolylineVertex(v10_1));//0
                polyline3.Vertexes.Add(new LwPolylineVertex(v11));//1
                polyline3.Vertexes[1].Bulge = Math.Tan((90) * pi / 180 / 4);
                fun.PolyFill(dxf, polyline3, 0.3, contour);

                LwPolyline polyline4 = new LwPolyline();
                polyline4.Vertexes.Add(new LwPolylineVertex(v12));
                polyline4.Vertexes.Add(new LwPolylineVertex(v12_1));//0
                polyline4.Vertexes.Add(new LwPolylineVertex(v13));//1
                polyline4.Vertexes[1].Bulge = -Math.Tan((90) * pi / 180 / 4);
                fun.PolyFill(dxf, polyline4, 0.3, contour);

                //第二部分--------------------------------------------------------------------------------------------
                //中心线
                Line centre_line3 = new Line(v14, v15);
                centre_line3.Layer = centre;
                centre_line3.Linetype = Linetype.Center;
                centre_line3.LinetypeScale = 5;
                dxf.AddEntity(centre_line3);

                Line centre_line3_1 = new Line(v24_1, v27_1);
                centre_line3_1.Layer = centre;
                centre_line3_1.Linetype = Linetype.Center;
                centre_line3_1.LinetypeScale = 5;
                dxf.AddEntity(centre_line3_1);

                //轮廓线
                LwPolyline polyline5 = new LwPolyline();
                polyline5.Vertexes.Add(new LwPolylineVertex(v16));
                polyline5.Vertexes.Add(new LwPolylineVertex(v17));
                polyline5.Vertexes.Add(new LwPolylineVertex(v18));
                polyline5.Vertexes.Add(new LwPolylineVertex(v19));
                polyline5.Vertexes.Add(new LwPolylineVertex(v20));
                polyline5.Vertexes.Add(new LwPolylineVertex(v21));
                polyline5.Vertexes.Add(new LwPolylineVertex(v22));
                polyline5.Vertexes.Add(new LwPolylineVertex(v23));
                polyline5.Vertexes.Add(new LwPolylineVertex(v24));
                polyline5.Vertexes.Add(new LwPolylineVertex(v25));
                polyline5.Vertexes.Add(new LwPolylineVertex(v26));
                polyline5.Vertexes.Add(new LwPolylineVertex(v27));
                polyline5.Vertexes.Add(new LwPolylineVertex(v28));
                polyline5.Vertexes.Add(new LwPolylineVertex(v29));
                polyline5.Vertexes.Add(new LwPolylineVertex(v30));
                polyline5.Vertexes.Add(new LwPolylineVertex(v31));
                polyline5.Vertexes.Add(new LwPolylineVertex(v32));
                polyline5.Vertexes.Add(new LwPolylineVertex(v16));
                fun.PolyFill(dxf, polyline5, 0.3, contour);

                LwPolyline polyline6 = new LwPolyline();
                polyline6.Vertexes.Add(new LwPolylineVertex(v21));
                polyline6.Vertexes.Add(new LwPolylineVertex(v31));
                fun.PolyFill(dxf, polyline6, 0.3, contour);

                LwPolyline polyline7 = new LwPolyline();
                polyline7.Vertexes.Add(new LwPolylineVertex(v23));
                polyline7.Vertexes.Add(new LwPolylineVertex(v28));
                fun.PolyFill(dxf, polyline7, 0.3, contour);

                LwPolyline polyline8 = new LwPolyline();
                polyline8.Vertexes.Add(new LwPolylineVertex(v24));
                polyline8.Vertexes.Add(new LwPolylineVertex(v27));
                fun.PolyFill(dxf, polyline8, 0.3, contour);

                LwPolyline polyline9 = new LwPolyline();
                polyline9.Vertexes.Add(new LwPolylineVertex(v33));
                polyline9.Vertexes.Add(new LwPolylineVertex(v38));
                fun.PolyFill(dxf, polyline9, 0.3, contour);

                //填充
                LwPolyline hatchpoly1 = new LwPolyline();
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v33));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v34));//0
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v35));//1
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v18));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v19));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v20));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v21));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v22));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v23));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v24));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v25));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v33));
                hatchpoly1.IsClosed = true;
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)hatchpoly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)hatchpoly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 10, hline1, harc1, hatching);

                LwPolyline hatchpoly2 = new LwPolyline();
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v36));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v37));//0
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v38));//1
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v26));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v27));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v28));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v29));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v30));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v31));
                hatchpoly2.Vertexes.Add(new LwPolylineVertex(v36));
                hatchpoly2.IsClosed = true;
                String[] htype2 = new String[100];
                Line[] hline2 = new Line[100];
                Arc[] harc2 = new Arc[100];
                int hnumst2 = hatchpoly2.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst2; i++)
                {
                    htype2[i] = hatchpoly2.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype2[i] == "Line")
                    {
                        hline2[i] = (Line)hatchpoly2.Explode()[i];
                    }
                    if (htype2[i] == "Arc")
                    {
                        harc2[i] = (Arc)hatchpoly2.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype2, hnumst2, 45, 10, hline2, harc2, hatching);

                //第三部分--------------------------------------------------------------------------------------------
                //中心线
                Line centre_line4 = new Line(v39, v40);
                centre_line4.Layer = centre;
                centre_line4.Linetype = Linetype.Center;
                centre_line4.LinetypeScale = 5;
                dxf.AddEntity(centre_line4);

                //轮廓线
                LwPolyline polyline10 = new LwPolyline();
                polyline10.Vertexes.Add(new LwPolylineVertex(v41));
                polyline10.Vertexes.Add(new LwPolylineVertex(v42));
                polyline10.Vertexes.Add(new LwPolylineVertex(v43));
                polyline10.Vertexes.Add(new LwPolylineVertex(v44));
                polyline10.Vertexes.Add(new LwPolylineVertex(v45));
                polyline10.Vertexes.Add(new LwPolylineVertex(v46));
                polyline10.Vertexes.Add(new LwPolylineVertex(v47));
                polyline10.Vertexes.Add(new LwPolylineVertex(v48));
                polyline10.Vertexes.Add(new LwPolylineVertex(v49));
                polyline10.Vertexes.Add(new LwPolylineVertex(v50));
                polyline10.Vertexes.Add(new LwPolylineVertex(v51));
                polyline10.Vertexes.Add(new LwPolylineVertex(v52));
                polyline10.Vertexes.Add(new LwPolylineVertex(v53));
                polyline10.Vertexes.Add(new LwPolylineVertex(v54));
                polyline10.Vertexes.Add(new LwPolylineVertex(v41));
                fun.PolyFill(dxf, polyline10, 0.3, contour);

                LwPolyline polyline11 = new LwPolyline();
                polyline11.Vertexes.Add(new LwPolylineVertex(v55));
                polyline11.Vertexes.Add(new LwPolylineVertex(v55_1));
                fun.PolyFill(dxf, polyline11, 0.3, contour);

                LwPolyline polyline12 = new LwPolyline();
                polyline12.Vertexes.Add(new LwPolylineVertex(v59));
                polyline12.Vertexes.Add(new LwPolylineVertex(v59_1));
                fun.PolyFill(dxf, polyline12, 0.3, contour);

                LwPolyline polyline13 = new LwPolyline();
                polyline13.Vertexes.Add(new LwPolylineVertex(v53));
                polyline13.Vertexes.Add(new LwPolylineVertex(v42));
                fun.PolyFill(dxf, polyline13, 0.3, contour);

                LwPolyline polyline14 = new LwPolyline();
                polyline14.Vertexes.Add(new LwPolylineVertex(v50));
                polyline14.Vertexes.Add(new LwPolylineVertex(v45));
                fun.PolyFill(dxf, polyline14, 0.3, contour);

                LwPolyline polyline15 = new LwPolyline();
                polyline15.Vertexes.Add(new LwPolylineVertex(v49));
                polyline15.Vertexes.Add(new LwPolylineVertex(v46));
                fun.PolyFill(dxf, polyline15, 0.3, contour);

                LwPolyline polyline16 = new LwPolyline();
                polyline16.Vertexes.Add(new LwPolylineVertex(v57));
                polyline16.Vertexes.Add(new LwPolylineVertex(v61));
                fun.PolyFill(dxf, polyline16, 0.3, contour);

                LwPolyline polyline17 = new LwPolyline();
                polyline17.Vertexes.Add(new LwPolylineVertex(v63));
                polyline17.Vertexes.Add(new LwPolylineVertex(v65));
                polyline17.Vertexes.Add(new LwPolylineVertex(v66));
                fun.PolyFill(dxf, polyline17, 0.3, contour);

                LwPolyline polyline18 = new LwPolyline();
                polyline18.Vertexes.Add(new LwPolylineVertex(v62));
                polyline18.Vertexes.Add(new LwPolylineVertex(v64));
                polyline18.Vertexes.Add(new LwPolylineVertex(v67));
                fun.PolyFill(dxf, polyline18, 0.3, contour);

                LwPolyline polyline19 = new LwPolyline();
                polyline19.Vertexes.Add(new LwPolylineVertex(v65));
                polyline19.Vertexes.Add(new LwPolylineVertex(v64));
                fun.PolyFill(dxf, polyline19, 0.3, contour);

                LwPolyline polyline20 = new LwPolyline();
                polyline20.Vertexes.Add(new LwPolylineVertex(v68));
                polyline20.Vertexes.Add(new LwPolylineVertex(v70));
                polyline20.Vertexes.Add(new LwPolylineVertex(v73));
                fun.PolyFill(dxf, polyline20, 0.3, contour);

                LwPolyline polyline21 = new LwPolyline();
                polyline21.Vertexes.Add(new LwPolylineVertex(v69));
                polyline21.Vertexes.Add(new LwPolylineVertex(v71));
                polyline21.Vertexes.Add(new LwPolylineVertex(v72));
                fun.PolyFill(dxf, polyline21, 0.3, contour);

                LwPolyline polyline22 = new LwPolyline();
                polyline22.Vertexes.Add(new LwPolylineVertex(v70));
                polyline22.Vertexes.Add(new LwPolylineVertex(v71));
                fun.PolyFill(dxf, polyline22, 0.3, contour);

                if (type == 3/*type.Equals("C型空心锥柄")*/)
                {
                    fun.drawcircle(dxf, v74, d6 / 2, 0.3, contour);
                }

                //填充
                LwPolyline hatchpoly3 = new LwPolyline();
                hatchpoly3.Vertexes.Add(new LwPolylineVertex(v55));
                hatchpoly3.Vertexes.Add(new LwPolylineVertex(v56));//0
                hatchpoly3.Vertexes.Add(new LwPolylineVertex(v57));//1
                hatchpoly3.Vertexes.Add(new LwPolylineVertex(v48));
                hatchpoly3.Vertexes.Add(new LwPolylineVertex(v49));
                hatchpoly3.Vertexes.Add(new LwPolylineVertex(v50));
                hatchpoly3.Vertexes.Add(new LwPolylineVertex(v51));
                hatchpoly3.Vertexes.Add(new LwPolylineVertex(v52));
                hatchpoly3.Vertexes.Add(new LwPolylineVertex(v53));
                hatchpoly3.Vertexes.Add(new LwPolylineVertex(v54));
                hatchpoly3.Vertexes.Add(new LwPolylineVertex(v55_1));
                hatchpoly3.Vertexes.Add(new LwPolylineVertex(v55));
                hatchpoly3.IsClosed = true;
                String[] htype3 = new String[100];
                Line[] hline3 = new Line[100];
                Arc[] harc3 = new Arc[100];
                int hnumst3 = hatchpoly3.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst3; i++)
                {
                    htype3[i] = hatchpoly3.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype3[i] == "Line")
                    {
                        hline3[i] = (Line)hatchpoly3.Explode()[i];
                    }
                    if (htype3[i] == "Arc")
                    {
                        harc3[i] = (Arc)hatchpoly3.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype3, hnumst3, 45, 10, hline3, harc3, hatching);

                LwPolyline hatchpoly4 = new LwPolyline();
                hatchpoly4.Vertexes.Add(new LwPolylineVertex(v59));
                hatchpoly4.Vertexes.Add(new LwPolylineVertex(v60));//0
                hatchpoly4.Vertexes.Add(new LwPolylineVertex(v61));//1
                hatchpoly4.Vertexes.Add(new LwPolylineVertex(v47));
                hatchpoly4.Vertexes.Add(new LwPolylineVertex(v46));
                hatchpoly4.Vertexes.Add(new LwPolylineVertex(v45));
                hatchpoly4.Vertexes.Add(new LwPolylineVertex(v44));
                hatchpoly4.Vertexes.Add(new LwPolylineVertex(v45));
                hatchpoly4.Vertexes.Add(new LwPolylineVertex(v42));
                hatchpoly4.Vertexes.Add(new LwPolylineVertex(v41));
                hatchpoly4.Vertexes.Add(new LwPolylineVertex(v59_1));
                hatchpoly4.Vertexes.Add(new LwPolylineVertex(v59));
                hatchpoly4.IsClosed = true;
                String[] htype4 = new String[100];
                Line[] hline4 = new Line[100];
                Arc[] harc4 = new Arc[100];
                int hnumst4 = hatchpoly4.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst4; i++)
                {
                    htype4[i] = hatchpoly4.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype4[i] == "Line")
                    {
                        hline4[i] = (Line)hatchpoly4.Explode()[i];
                    }
                    if (htype4[i] == "Arc")
                    {
                        harc4[i] = (Arc)hatchpoly4.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype4, hnumst4, 45, 10, hline4, harc4, hatching);

                //标注------------------------------------------------------------------------------------------
                //定义
                double height = 1;
                double arrowsize = 1;
                double exline = 1;

                //第一部分---------------------------------------------------
                //直线标注
                //下侧
                fun.dimrot1(dxf, v12, v10, 180, d2 / 2, 1, height, arrowsize, exline, "b1=" + Math.Round(b1, 1), "", "");

                //箭头
                fun.jt1(dxf, v7, -135, 5, 1, "r1", height);

                //形位公差
                fun.gcbz(dxf, new Vector2(v10.X, v10.Y - d2 / 2), 5, 0, 0.1, 0, 2.5, 0.5, 0.5, "A", "0.05", height, "dcd", 0.25);

                //第二部分--------------------------------------------
                //直线标注
                //上侧
                fun.dimrot1(dxf, v19, v33, 0, d2 / 2, 1, height, arrowsize, exline, "l4=" + Math.Round(l4, 1), "", "");
                fun.dimrot1(dxf, v27, v26, 0, d2 / 6, 1, height, arrowsize, exline, "l5*30°=" + Math.Round(l5, 1), "", "");

                //左侧
                fun.dimrot1(dxf, v19, v30, 90, l1, 1, height, arrowsize, exline, "φd5=" + Math.Round(d5, 1), "", "");
                fun.dimrot1(dxf, v16, v32, 90, l1 * 0.3, 1, height, arrowsize, exline, "φd3=" + Math.Round(d3, 1), "", "");

                //右侧
                fun.dimrot1(dxf, v24_1, v27_1, -90, l1 * 0.6, 1, height, arrowsize, exline, "φd2=" + Math.Round(d2, 1), "", "");
                fun.dimrot1(dxf, v33, v38, -90, l1, 1, height, arrowsize, exline, "φd1=" + Math.Round(d1, 1), "", "");

                //下侧
                fun.dimrot1(dxf, v30, v29, 180, d2 * 0.3, 1, height, arrowsize, exline, "l7=" + Math.Round(l7, 1), "", "");
                fun.dimrot1(dxf, v27_1, v38, 180, d2 * 0.5, 1, height, arrowsize, exline, "l2=" + Math.Round(l2, 1), "", "");
                fun.dimrot1(dxf, v30, v38, 180, d2 * 0.7, 1, height, arrowsize, exline, "l3=" + Math.Round(l3, 1), "", "");
                fun.dimrot1(dxf, v32, v38, 180, d2, 1, height, arrowsize, exline, "l1=" + Math.Round(l1, 1), "", "");

                //角度标注
                fun.jdbz1(dxf, new Line(v26, new Vector2(v26.X + 0.1, v26.Y)), new Line(v26, fun.Polar(v26, -2.87 * pi / 180, 0.1)), 80, "2°51'45''", height);

                //形位公差
                fun.gcbz(dxf, new Vector2(v38.X, v38.Y - d2 * 0.8), 5, 0, 0.1, 0, 2.5, 0.5, 0.5, "A", "0.05", height, "qtd", 0.25);
                fun.gcbz_two(dxf, fun.Polar(v24_1, (180 - 2.87) * pi / 180, 0.5), 3, -90, 8, 0, 2.5, 0.5, 0.5, "t", height, "mlkd", 0.25);

                //基准
                fun.jz(dxf, new Vector2(v23.X + 1, v23.Y + 1), 90, 5, "A");

                //锥度
                fun.jtbz(dxf, fun.Polar(v28, -2.87 * pi / 180, fun.CalDistance(v28, v27) * 2 / 3), 80, 10, 4, "1:10", 0.5, height);

                //第三部分-----------------------------------------------------------------------
                //直线标注
                //上侧
                fun.dimrot1(dxf, v54, v41, 0, d2 / 2, 1, height, arrowsize, exline, "φd4=" + Math.Round(d4, 1), "", "");

                //右侧
                fun.dimrot1(dxf, v71, v72, -90, d4 / 6, 1, height, arrowsize, exline, "φl6=" + Math.Round(l6, 1), "", "");

                //角度标注
                fun.jdbz1(dxf, new Line(v64, new Vector2(v64.X, v64.Y - 0.1)), new Line(v64, fun.Polar(v64, -45 * pi / 180, 0.1)), 20, "45°", height);
            }
            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            Vector2 p0 = new Vector2(0, 0);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }


            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }
    }
}
